package com.thinkfit.jy.view;

import android.app.Activity;
import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/*适配 recycleView GridLayoutManager 列 左右贴边，中间居中*/
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    private Activity mContext;
    private int space;  //位移间距
    private int mColumnCount;  //列数
    public SpaceItemDecoration(int space, Activity context,int columnCount) {
        this.space = space;
        this.mContext=context;
        this.mColumnCount=columnCount;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

        int position=parent.getChildAdapterPosition(view) %mColumnCount;
        outRect.left=position*(space/(mColumnCount-1) -space/mColumnCount );

    }

}
